package com.ss.plugins.sql.statics;

import com.ss.core.exceptions.SummerCustomSqlException;
import com.ss.plugins.sql.core.CustomSql;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

/**
 * 用于存储Apply转换信息的静态类
 * @author xia17
 * @date 2019/8/9 15:58
 */
@Slf4j
public class CustomSqlMap {
    private static Map<String, CustomSql> customSqlMap;

    public static void put(String name,CustomSql customSql){
        if (customSqlMap == null){
            customSqlMap = new HashMap<>(16);
        }
        customSqlMap.put(name,customSql);
        log.info("已加载" + name);
    }

    public static CustomSql get(Class clz){
        if (customSqlMap == null){
            throw new SummerCustomSqlException("没有扫描到申请类");
        }
        CustomSql customSql = customSqlMap.get(clz.getName());
        if (customSql == null){
            throw new SummerCustomSqlException("没有找到申请类");
        }
        return customSql;
    }

}
